package com.elcom.roaming.module.synthesis.match;

import com.elcom.roaming.common.config.ConfigModule;
import com.elcom.roaming.common.util.match.ObjectKey;

public class MSRNKey extends ObjectKey {

	public static final char ISUP='I';
	public static final char PRN='P';
	
	int seq;
	String msrn;
	char type;
	
	public MSRNKey(int seq, String msrn, String time, char type) {
		this.seq = seq;
		this.msrn = msrn;
		this.setPutTime(time);
		this.type = type;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof MSRNKey)) return false;
		
		MSRNKey cmpObj = (MSRNKey) obj;
		
		if (this == cmpObj) return true;
//		if (this.seq == cmpObj.seq && 
//				this.getPutTime().equals(cmpObj.getPutTime()) && 
//				this.msrn.equals(cmpObj.msrn) ) return true;
		// else 
		
		if (this.msrn.equals(cmpObj.msrn) && 
				Math.abs(this.getPutTimeInMs() - cmpObj.getPutTimeInMs()) < ConfigModule.MISS_CALL_TIMEOUT * 1000 &&
				this.type != cmpObj.type) return true;
		
		return false;
	}

	@Override
	public int hashCode() {
		return msrn.hashCode();
	}

	@Override
	public String toString() {
		return "seq=" + seq +
				"|time=" + getPutTime() +
				"|msrn=" + msrn;
	}

}
